/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testadventure;

import edu.clemson.cs.hamptos.adventure.AdventureCommand;
import edu.clemson.cs.hamptos.adventure.AdventureEngine;
import edu.clemson.cs.hamptos.adventure.AdventureTarget;
import edu.clemson.cs.hamptos.adventure.AdventureWindow;
import edu.clemson.cs.hamptos.adventure.VerbStrategyAlt;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

/**
 *<p>Implements the <code>VerbStrategyAlt</code> interface.</p>
 * @author Nicks
 */
public class VerbReload implements VerbStrategyAlt {
    /**
     * <p>Constructs a new instance of <code>VerbReload</code>.</p>
     */
    VerbReload()
    {
        verbs.add("load");
        verbs.add("reload");
    }
    
    protected final HashSet<String> verbs = new HashSet<String>();
    
    @Override
    public void doCommand(AdventureCommand c, AdventureEngine e, AdventureWindow w) {
        AdventureTarget thedo = c.getDirectObject();
        AdventureTarget theio = c.getIndirectObject();
        
        HashMap<String, Integer> dostats = thedo.getStats();
        HashMap<String, Integer> iostats = theio.getStats();
        
        if(dostats.get("enabled") == 1)
        {
            w.println(thedo.getShortDescription() + " is already " + c.getVerb());
            return;
        }
        
        dostats.put("charges", iostats.get("charges") + dostats.get("charges"));
        
        w.println("You " + c.getVerb() + " " + thedo.getShortDescription() 
                    + " with " + theio.getShortDescription());
        
        thedo.listen(e, w);
        
        try
        {
            e.removeFromPlayerInventory(theio);
            e.getPlayerLocation().removeLocalTarget(theio);
        }
        catch (IllegalStateException ex)
        {
            e.getPlayerLocation().removeLocalTarget(theio);
        }
    }

    @Override
    public String getName() {
        return "VerbReload";
    }

    @Override
    public Set<String> getVerbs() {
        return new HashSet<String>(verbs);
    }
}